/**
 * 
 */
package com.zoiz.plus.extend;

import java.io.File;
import java.util.Map;


import com.zoiz.dbutils.ThreadHolder;
import com.zoiz.plus.renderer.BinaryRenderer;
import com.zoiz.plus.renderer.FileRenderer;
import com.zoiz.plus.renderer.JavaScriptRenderer;
import com.zoiz.plus.renderer.Renderer;
import com.zoiz.plus.renderer.TemplateRenderer;
import com.zoiz.plus.renderer.TextRenderer;

/**
 * 一目了然
 * 
 * @author chenjiankang
 * 
 */
public class Controller {
	
	// json
	protected Renderer renderJson(Object obj) {
		return new JsonRender(obj);
	}

	// template
	protected final Renderer render(String path) {
		Map<String, Object> _model = ThreadHolder.getHolder().get_model();
		//ThreadHolder.getHolder().set_model(null);
		return new TemplateRenderer(path, _model);
	}

	// redirect
	protected final Renderer redirect(String s) {
		return new RedirectRender(s);
	}

	// script
	protected final Renderer renderScript(String s) {
		return new JavaScriptRenderer(s);
	}

	// text
	protected final Renderer renderText(String text) {
		return new TextRenderer(text);
	}

	// file
	protected final Renderer renderFile(File f) {
		return new FileRenderer(f);
	}

	// file
	protected final Renderer renderFile(String filepath) {
		return new FileRenderer(filepath);
	}

	// binary
	protected final Renderer renderBinary(byte[] data) {
		BinaryRenderer br = new BinaryRenderer();
		br.setData(data);
		return br;
	}
	//xml
	protected final Renderer renderXML(String xml){
		TextRenderer tr=new TextRenderer(xml);
		tr.setContentType("application/xml");
		return tr;
	}

	protected final void push(String key, Object o) {
		ThreadHolder.getHolder().get_model().put(key, o);
	}
}
